﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ApplLogic.ApplClasses;
using ConnectionObjects;
using TCPClient.RequestsToServerHandlers;
using TCPClient.UI.LogicForUserControls;
using TCPClient.UI.UserControls;

namespace TCPClient.UI
{
    public partial class WorkerMainForm : Form
    {
        private RequestsToServerHandlerForWorker m_WorkHandlerRef = null;
        public WorkerMainForm(RequestsToServerHandler handler)
        {
            InitializeComponent();
            scMainUserControl1.WorkerRequestHandler = handler as RequestsToServerHandlerForWorker;
            m_WorkHandlerRef = handler as RequestsToServerHandlerForWorker;
            Text += string.Format(" - {0}", m_WorkHandlerRef.LoggedInWorker.PersonalDetails.FullName);
            scMainUserControl1.DateChanged += enableStatisticsMenuBar;
        }

        private void enableStatisticsMenuBar(object sender, EventArgs e)
        {
            DateEventArgs args = e as DateEventArgs;
            (this.toolStrip1.Items[6] as ToolStripDropDownButton).DropDownItems[1].Enabled = ScMainUserControlLogic.Instance.GetWorkerStat(
                args.StartTime.AddHours(-1), args.EndTime.AddHours(1), m_WorkHandlerRef.LoggedInWorker.PersonalDetails.Id) != null;
        }

        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void DetailsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PersonalDetailsForm prForm = new PersonalDetailsForm(m_WorkHandlerRef.LoggedInWorker);
            prForm.ShowDialog();

        }

        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.scMainUserControl1.RefreshAll();
        }

        private void toolStripButtonPersonalDetails_Click(object sender, EventArgs e)
        {
            PersonalDetailsForm prForm = new PersonalDetailsForm(m_WorkHandlerRef.LoggedInWorker);
            prForm.ShowDialog();
        }

        private void toolStripButtonREFRESH_Click(object sender, EventArgs e)
        {
            this.scMainUserControl1.RefreshAll();
        }

        private void toolStripButtonExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void toolStripButtonStat_Click(object sender, EventArgs e)
        {
            WorkerStatForm wmsf = new WorkerStatForm(ScMainUserControlLogic.Instance, m_WorkHandlerRef.LoggedInWorker.PersonalDetails.Id, eStatType.Weekly);
            wmsf.ShowDialog();
        }

        private void toolStripMenuItemWeekStat_Click(object sender, EventArgs e)
        {
            WorkerStatForm wmsf = new WorkerStatForm(ScMainUserControlLogic.Instance, m_WorkHandlerRef.LoggedInWorker.PersonalDetails.Id, eStatType.Weekly);
            wmsf.ShowDialog();
        }

        private void toolStripMenuItemAggrStat_Click(object sender, EventArgs e)
        {
            WorkerStatForm wmsf = new WorkerStatForm(ScMainUserControlLogic.Instance, m_WorkHandlerRef.LoggedInWorker.PersonalDetails.Id, eStatType.Aggregative);
            wmsf.ShowDialog();
        }


    }
}
